import { createApp } from 'vue'
import App from './App.vue'
import router from './routers'
import store from '@/store'
import plugins from './plugins'
import i18n from '@/plugins/i18n'
import '@/mock/index'
import 'virtual:svg-icons-register'
import ployfill from './ployfill'
import { useLoginStore } from '@/store/Login'
import { useRouterStore } from '@/store/Router'
import { _addRoutes } from './routers/resolveRouter'
const app = createApp(App)
// 插件
app.use(plugins)
// 国际化
app.use(i18n)
// pinia
app.use(store)
async function init() {
  const store = useLoginStore()
  if (store.user.token) {
    // 添加动态路由
    const router_store = useRouterStore()
    const { user } = store
    await router_store.SETASYNCROUTER(user)
    _addRoutes(router_store.asyncRouter!, router)
  }
  ployfill()
  app.use(router).mount('#app')
}
init()
